var common = require('../../utils/common.js');
const app = getApp()
Page({
  data: {
    classification: [],
    current: 0,
    items: [],
    onlyWx: false,
    itemloading: true,
    itemIsShow: false,
    page: 1,
    categoryId: '',
    userInfo: app.globalData.userInfo,
    tipshow: true,
    more: true,
    currentTab: 0,
    rToolsShow: false,
    nineloading: true,
    currentTab: 0,
    todayitems:[],
    nineitems:[],
    seachitems:[],
    itemloading: true,
    todayloading: true,
    nineloading: true,
    seachloading: true,
    from: '',
    ninePageNum: 1
  },
  onLoad: function (options) {
    console.log(options)
    this.setData({
      from: options.from
    })
    this.getnineitemdata()
    console.log(app.globalData.userInfo)
    this.setData({
      userInfo: app.globalData.userInfo
    })
  },
  getnineitemdata() {
    const that = this
    isChoiceness = false
    common.post({
      url: '/app/v2/goods/freeShipping99', data: { pageNo: 1,sessionId: app.globalData.sessionId}
    })
      .then((res) => {
        that.setData({
          nineitems: res.data.data,
          loading: false
        });
        console.log(that.data.nineitems)
      }).catch((res) => {
        console.log(res)
      })
  },
  getnineitemdatapage() {
    const that = this;
    var page = that.data.ninePageNum + 1;
    common.post({ url: '/app/v2/goods/freeShipping99', data: {pageNo: page,sessionId: app.globalData.sessionId } })
      .then((res) => {
        var data = that.data.nineitems;
        console.log(res.data)
        if (that.data.ninePageNum * 10 < res.data.total) {
          that.setData({
            ninePageNum: page
          });
          var postList = res.data.data;
          for (let i = 0; i < postList.length; i++) {
            let tmp = postList[i];
            data.push(tmp);
          }
          setTimeout(() => {
            console.log(data)
            that.setData({
              nineitems: data,
            })
          }, 300);
        } else {
          console.log('没有了')
          that.setData({
            nineloading: false
          })
          wx.showToast({
            title: '没有了',
            icon: 'none',
            duration: 2000
          })
        }

      }).catch((res) => {
        console.log(res)

      })
  },
  onReachBottom() {
    console.log('bottom')
    this.getnineitemdatapage()
  },
  buybtn(e) {
    if (e.currentTarget.dataset.item.is99) {
      wx.navigateTo({
        url: '/pages/freeItemdetail/freeItemdetail?sku=' + e.currentTarget.dataset.item.skuId
      })
    }
  },
  closeTip(){
    this.setData({
      tipshow: false
    })
  },
  totop(){
    this.setData({
      scrollTop: 0
    })
  },
  seachlink: function () {
    wx.navigateTo({
      url: '/pages/seach/seach'
    })
  },

})